package gui;



import javax.swing.JFrame;
import javax.swing.JLabel;

import java.awt.BorderLayout;

import javax.swing.JSplitPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.net.UnknownHostException;



public class ConnectGUI extends JFrame implements ActionListener{
	
	private P2PGUI gui;
	private JTextField LoginField;
	
	public ConnectGUI(P2PGUI gui) {
		super();
		this.gui = gui;
		
		
		this.setSize(259, 212);
		setName("Connect_Frame");
		setTitle("P2P_Chat");
		getContentPane().setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 68, 226, 95);
		getContentPane().add(panel);
		panel.setLayout(null);
		
		JButton btnConnect = new JButton("Connect");
		btnConnect.setBounds(62, 52, 95, 38);
		panel.add(btnConnect);
		btnConnect.addActionListener(this);
		
		LoginField = new JTextField();
		LoginField.setBounds(101, 11, 115, 30);
		panel.add(LoginField);
		LoginField.setColumns(10);
		
		JLabel lblLogin = new JLabel("Login");
		lblLogin.setFont(new Font("Tahoma", Font.PLAIN, 19));
		lblLogin.setBounds(21, 11, 60, 30);
		panel.add(lblLogin);
		
		JLabel lblNewLabel = new JLabel("INSA");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 33));
		lblNewLabel.setForeground(new Color(255, 0, 0));
		lblNewLabel.setBounds(78, 11, 82, 57);
		getContentPane().add(lblNewLabel);
		
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public String getLogin() {
		return LoginField.getText();
	}

	public void setLogin(String arg0){
		LoginField.setText(arg0);
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(!this.getLogin().equals("")){
			//create user
			try {
				gui.connectGUI(this.getLogin());
			} catch (UnknownHostException e) {
				e.printStackTrace();
			}
		}
		
	}
}
